package com.itcam.project.controller;

import com.itcam.iahcommon.model.entity.User;
import com.itcam.iahcommon.model.vo.BiResponse;
import com.itcam.iahcommon.response.BaseResponse;
import com.itcam.iahcommon.utils.ResultUtils;
import com.itcam.project.model.dto.chart.GenChartByAIRequest;
import com.itcam.project.service.ChartService;
import com.itcam.project.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 帖子接口
 */
@RestController
@RequestMapping("/chart")
@Slf4j
public class ChartController {

    @Resource
    private UserService userService;

    @Resource
    private ChartService chartService;

    /**
     * todo:智能分析（同步）
     *
     * @param multipartFile
     * @param genChartByAIRequest
     * @param request
     * @return
     */
    @PostMapping("/gen")
    public BaseResponse<BiResponse> genChartByAI(@RequestPart("file") MultipartFile multipartFile,
                                                 GenChartByAIRequest genChartByAIRequest, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        Long userId = loginUser.getId();
        return ResultUtils.success(chartService.genChartByAI(multipartFile,genChartByAIRequest,userId).getData());
    }

    /**
     * 智能分析（异步）
     * @return
     */
    @PostMapping("/gen/async")
    public BaseResponse<BiResponse> genChartByAIAsync(@RequestPart("file") MultipartFile multipartFile,
                                                      GenChartByAIRequest genChartByAIRequest,HttpServletRequest request){
        User loginUser = userService.getLoginUser(request);
        Long userId = loginUser.getId();
        return ResultUtils.success(chartService.genChartByAIAsync(multipartFile,genChartByAIRequest,userId).getData());
    }

    /**
     * 智能分析（异步消息队列）
     * @return
     */
    @PostMapping("/gen/async/mq")
    public BaseResponse<BiResponse> genChartByAIAsyncMq(@RequestPart("file") MultipartFile multipartFile,
                                                      GenChartByAIRequest genChartByAIRequest,HttpServletRequest request){
        User loginUser = userService.getLoginUser(request);
        Long userId = loginUser.getId();
        return ResultUtils.success(chartService.genChartByAIAsyncMq(multipartFile,genChartByAIRequest,userId).getData());
    }
}
